package com.baidu.recognition.controller;

import com.alibaba.fastjson.JSONObject;
import com.baidu.recognition.config.baidu.BaiduApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liuzhiqiang
 */
@RestController
@Slf4j
@CrossOrigin
@Api(tags = {"音频文件转写"})
@RequestMapping("transfer")
public class AudioFileTransferController {

    @Autowired
    private BaiduApi baiduApi;

    @ApiOperation(value = "创建音频转写任务")
    @PostMapping("createTask")
    @ApiImplicitParam(name = "speechUrl", value = "可使用百度云对象存储进行音频存储，生成云端可外网访问的url链接，音频大小不超过500MB", dataType = "String", paramType = "query", defaultValue = "https://platform.bj.bcebos.com/sdk%2Fasr%2Fasr_doc%2Fdoc_download_files%2F16k.pcm")
    public JSONObject createTask(String speechUrl) {
        JSONObject jsonObject = baiduApi.createTask(speechUrl);
        return jsonObject;
    }


    @ApiOperation(value = "查询音频转写任务结果")
    @PostMapping("queryTask")
    public JSONObject queryTask(@RequestBody List<String> taskIds) {
        JSONObject jsonObject = baiduApi.queryTask(taskIds);
        return jsonObject;
    }
}
